<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=640px,user-scalable=no,target-densitydpi=device-dpi" />
		<link rel="stylesheet" href="css/css.css" type="text/css" />
		<script type="text/javascript" src='js/jquery.min.js'></script>
		<script type="text/javascript" src='js/main_in.js'></script>
		<script type="text/javascript" src='js/mui.min.js'></script>
		<title>主页</title>
		<script type="text/javascript">
//取消浏览器的所有事件，使得active的样式在手机上正常生效
document.addEventListener('touchstart',function(){
    return false;
},true);
// 禁止选择
document.oncontextmenu=function(){
	return false;
};			
var wgtVer=null;
// H5 plus事件处理
var as='pop-in';// 默认窗口动画
function plusReady(){
	// 获取本地应用资源版本号
    plus.runtime.getProperty(plus.runtime.appid,function(inf){
        wgtVer=inf.version;
        console.log("当前应用版本："+wgtVer);
        $("#edition").html("当前版本："+wgtVer)
    });
	// 隐藏滚动条
	plus.webview.currentWebview().setStyle({scrollIndicator:'none'});
	var first = null;
	mui.back = function(){
	    //首次按键，提示‘再按一次退出应用’
	    
	    if(!first){
	        first = new Date().getTime();
	        mui.toast('再按一次退出应用');
	        setTimeout(function(){
	            first = null;
	        },1000);
	    }else{
	        if(new Date().getTime()-first<1000){
	           plus.runtime.quit();
	       }
		}
//	    alert(e.keyType+"\n"+e.keyCode);
	    return false;
	}
	// Android处理返回键
	compatibleAdjust();
}
if(window.plus){
	plusReady();
}else{
	document.addEventListener('plusready',plusReady,false);
	document.addEventListener('plusready',checkUpdate,false);
}
///ceshi
// 检测更新

var checkUrl="http://insure.unair.cn/grade/check.php";
function checkUpdate(){
//  plus.nativeUI.showWaiting("检测更新...");
    var xhr=new XMLHttpRequest();
    xhr.onreadystatechange=function(){
    	
        switch(xhr.readyState){
            case 4:
            plus.nativeUI.closeWaiting();
            if(xhr.status==200){
                console.log("检测更新成功："+xhr.responseText);
                
                var newVer=xhr.responseText;
                if(wgtVer&&newVer&&(wgtVer!=newVer)){
                    downWgt();  // 下载升级包
                }else{
//                  plus.nativeUI.alert("无新版本可更新！");
                }
            }else{
//              console.log("检测更新失败！");
//              plus.nativeUI.alert("检测更新失败！");
            }
            break;
            default:
            break;
        }
    }
    xhr.open('GET',checkUrl);
    xhr.send();
}
// 下载wgt文件
//var wgtUrl="http://alipay.unair.cn/grade/insure_grade.wgt";
//function downWgt(){
//	location.href="http://a.app.qq.com/o/simple.jsp?pkgname=com.honorwater.insure";
////  plus.nativeUI.showWaiting("下载更新包...");
////  plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){
////  	alert(JSON.stringify(d));
////  	alert(1);
////  	alert(JSON.stringify(status))
////      if ( status == 200 ) { 
////          console.log("下载更新包成功："+d.filename);
////          installWgt(d.filename); // 安装wgt包
////      } else {
////          console.log("下载更新包失败！");
////          plus.nativeUI.alert("下载更新包失败！");
////      }
////      plus.nativeUI.closeWaiting();
////  }).start();
//}
function downWgt(){
	var url="http://insure.unair.cn/grade/yundanfuwu.apk";
	var w = plus.nativeUI.showWaiting("下载更新包...");
	var dtask = plus.downloader.createDownload( url, {}, function ( d, status ) {
	    if ( status == 200 ) { // 下载成功
	        var path = d.filename;
//	        console.log(d.filename);
	        w.close();
	        installWgt(path);
//	        alert( "下载成功" ); 
	    } else {//下载失败
	        alert( "下载更新失败，请联系客服" ); 
	    }  
	});
	dtask.start();
}
// 更新应用资源
function installWgt(path){
    plus.nativeUI.showWaiting("安装更新包...");
    plus.runtime.install(path,{},function(){
        plus.nativeUI.closeWaiting();
        console.log("安装更新包成功！");
        plus.nativeUI.alert("应用资源更新完成！",function(){
            plus.runtime.restart();
        });
    },function(e){
        plus.nativeUI.closeWaiting();
        console.log("安装更新包失败["+e.code+"]："+e.message);
        plus.nativeUI.alert("安装更新包失败["+e.code+"]："+e.message);
    });
}
///ceshi

// DOMContentLoaded事件处理
var _domReady=false;
document.addEventListener('DOMContentLoaded',function(){
	_domReady=true;
	compatibleAdjust();
},false);
// 兼容性样式调整
var _adjust=false;
function compatibleAdjust(){
	if(_adjust||!window.plus||!_domReady){
		return;
	}
	_adjust=true;
	// iOS平台特效
	if('iOS'==plus.os.name){
		document.getElementById('content').className='scontent';	// 使用div的滚动条
		if(navigator.userAgent.indexOf('StreamApp')>=0){	// 在流应用模式下显示返回按钮
			document.getElementById('back').style.visibility='visible';
		}
	}
	// 预创建二级窗口
//	preateWebviews();
	// 关闭启动界面
		plus.navigator.setStatusBarBackground('#D74B28');
	setTimeout(function(){
		plus.navigator.closeSplashscreen();
	},200);
}
///////
			$(function(){
				var loginname = window.localStorage["loginname"];
				if(loginname == null || loginname == '' || loginname == undefined){
					location.href="user/login.html";
				}
			})
//////////
// 处理点击事件
var _openw=null;
/**
 * 点击打开新窗口
 * @param {Object} id	加载的页面地址，也用作窗口标识
 * @param {Object} a	页面动画内心，默认使用全局as设置的值
 * @param {Object} s	是否不显示窗口
 */
function clicked(id,a,s){
	if(_openw){return;}
	a||(a=as);
	_openw=preate[id];
	if(_openw){
		_openw.showded=true;
		_openw.show(a,null,function(){
			_openw=null;//避免快速点击打开多个页面
		});
	}else{
//		var wa=plus.nativeUI.showWaiting();
//		_openw=plus.webview.create(id,id,{scrollIndicator:'none',scalable:false,popGesture:'hide'},{preate:true});//复用二级页面
		_openw=plus.webview.create(id,id,{scrollIndicator:'none',scalable:false,popGesture:'close'});
		preate[id]=_openw;
		_openw.addEventListener('loaded',function(){//叶面加载完成后才显示
//		setTimeout(function(){//延后显示可避免低端机上动画时白屏
//			wa.close();
			_openw.showded=true;
			s||_openw.show(a,null,function(){
				_openw=null;//避免快速点击打开多个页面
			});
			s&&(_openw=null);//避免s模式下变量无法重置
//		},10);
		},false);
		_openw.addEventListener('hide',function(){
			_openw&&(_openw.showded=true);
			_openw=null;
		},false);
		_openw.addEventListener('close',function(){//页面关闭后可再次打开
			_openw=null;
			preate[id]&&(preate[id]=null);//兼容窗口的关闭
		},false);
	}
}
// 预创建二级页面
var preate={};
function preateWebviews(){
	preateWebivew('plus/webview.html');
	var plist=document.getElementById('plist').children;
	// 由于启动是预创建过多Webview窗口会消耗较长的时间，所以这里限制仅创建5个
	for( var i=0;i<plist.length&&i<2;i++){
		var id=plist[i].id;
		id&&(id.length>0)&&preateWebivew(id);
	}
}
function preateWebivew(id){
	if(!preate[id]){
		var w=plus.webview.create(id,id,{scrollIndicator:'none',scalable:false,popGesture:'hide'},{preate:true});
		preate[id]=w;
		w.addEventListener('close',function(){//页面关闭后可再次打开
			_openw=null;
			preate[id]&&(preate[id]=null);//兼容窗口的关闭
		},false);
	}
}
// 清除预创建页面(仅)
function preateClear(){
	for(var p in preate){
		var w=preate[p];
		if(w&&w.showded&&!w.isVisible()){
			w.close();
			preate[p]=null;
		}
	}
}

/////////////

			
		</script>
	</head>
	<body>
		<div class="app_head">
            <div style="font-size: 1.8em;text-indent: 15px;" class="app_prev"></div>
            <div class="app_head_text">乾龙快运运单服务</div>
            <div class="app_prev"></div>
        </div>
        <div id="pull" class="home_main">
         
                <div class="home_main_g home_main_1" onclick="clicked('bargain/bgadd.html')">
                    <div class="home_main_g_k"></div>
                    <div class="home_main_g_img"><img src="./img/home_1.png" /></div>
                    <div class="home_main_g_k home_main_g_text">在线开单</div>
                </div>
                <div class="home_main_k"></div>
                <div class="home_main_g home_main_2" onclick="clicked('bargain/bgsearch.html')">
                    <div class="home_main_g_k"></div>
                    <div class="home_main_g_img"><img src="./img/home_2.png" /></div>
                    <div class="home_main_g_k home_main_g_text">开单记录</div>
                </div>
                
                <div class="home_main_g home_main_3" onclick="clicked('passenger/addr_search.html')">
                    <div class="home_main_g_k"></div>
                    <div class="home_main_g_img"><img src="./img/home_3.png" /></div>
                    <div class="home_main_g_k home_main_g_text">资料维护</div>
                </div>
                <div class="home_main_k"></div>
                <div class="home_main_g home_main_4" onclick="clicked('etc/search.html')" >
                    <div class="home_main_g_k"></div>
                    <div class="home_main_g_img"><img src="./img/home_4.png" /></div>
                    <div class="home_main_g_k home_main_g_text">ETC申请</div>
                </div>
                
                <div class="home_main_g home_main_5" onclick="clicked('etc/topay.html')">
                    <div class="home_main_g_k"></div>
                    <div class="home_main_g_img"><img src="./img/home_5.png" /></div>
                    <div class="home_main_g_k home_main_g_text">使用说明</div>
                </div>
                <div class="home_main_k"></div>
                <div class="home_main_g home_main_6" onclick="clicked('./myinfo/myinfo.html')">
                    <div class="home_main_g_k"></div>
                    <div class="home_main_g_img"><img src="./img/home_6.png" /></div>
                    <div class="home_main_g_k home_main_g_text">我的</div>
                </div>
                
                <div class="home_main_g home_main_7" onclick="clicked('./myinfo/wx.html')">
                    <div class="home_main_g_k"></div>
                    <div class="home_main_g_img"><img src="./img/home_6.png" /></div>
                    <div class="home_main_g_k home_main_g_text">新增</div>
                </div>
                <div class="home_main_k"></div>
                <div class="home_main_g home_main_8" onclick="clicked('./myinfo/wx.html')">
                    <div class="home_main_g_k"></div>
                    <div class="home_main_g_img"><img src="./img/home_6.png" /></div>
                    <div class="home_main_g_k home_main_g_text">敬请期待</div>
                </div>
                
                <div class="edition" id="edition"></div>
           
        </div>
        
	</body>
</html>
